
from D5Core.Details.D5Api import D5Api
from D5Core.D5Common import D5Singleton
import json
from D5Core.Details.D5Api import APIRequestType

@D5Singleton
class RenderTool:
    """
    渲染工具类，用于处理渲染相关的操作。
    该类使用单例模式（通过D5Singleton装饰器实现），确保在整个应用程序中
    只有一个RenderTool实例，用于集中管理所有渲染操作。
    :ivar __render_tool_sig: 渲染工具信号实例
    :vartype __render_tool_sig: RenderToolSig
    """
    def __init__(self):
        pass 

    def render_photo(self, path: str,  width: int, height: int,
    channel_graph_choose:list,channel_graph:int,format:int,scene_name:str = ""):
        req_id = D5Api().generate_uuid()
        content = {
            "id": req_id,
            "path": path,
            "width": width,
            "height": height,
            "channel_graph_choose": channel_graph_choose,
            "channel_graph": channel_graph,
            "format": format,
            "proportion":3,
            "aspectRatio": 0,
            "pushback": False,
            "sceneName": scene_name,
            "resolution":3,
            "scale": 3  # 使用自定义尺寸
        }
        payload = {
            "uuid": req_id,
            "type": APIRequestType.RENDER_PHOTO.value,
            "content": json.dumps(content)
        }
        res = D5Api().render_photo_sync(req_id, json.dumps(payload), 100)
        return res
        